import { Request, Response } from 'express'
import { playbackService } from '../services/playback'

export const startRecording = async (req: Request, res: Response) => {
  try {
    const { roomId } = req.params
    const playback = await playbackService.startRecording(roomId)
    res.json({
      message: '开始录制',
      playback: {
        id: playback._id,
        title: playback.title,
        status: playback.status,
      },
    })
  } catch (error) {
    res.status(500).json({ message: error.message })
  }
}

export const getPlaybacks = async (req: Request, res: Response) => {
  try {
    const { roomId } = req.params
    const { page, limit } = req.query
    const result = await playbackService.getPlaybacks(roomId, Number(page), Number(limit))
    res.json(result)
  } catch (error) {
    res.status(500).json({ message: error.message })
  }
}

export const getPlayback = async (req: Request, res: Response) => {
  try {
    const { playbackId } = req.params
    const playback = await playbackService.getPlayback(playbackId)
    res.json(playback)
  } catch (error) {
    res.status(500).json({ message: error.message })
  }
}
